// 同时发送异步请求的次数
let ajaxtimes = 0

export const request = params => {
    ajaxtimes++

    wx.showLoading({
        title: "加载中",
        mask: true,
        
    });

    let baseUrl = "https://api-hmugo-web.itheima.net/api/public/v1"
    return new Promise((resolve, reject) => {
        wx.request({
            ...params,
            url: baseUrl + params.url,
            success: (result)=>{
                resolve(result.data.message)
            },
            fail: (err)=>{
                reject(err)
            },
            complete: ()=>{
                ajaxtimes--
                //关闭 加载中
                if (ajaxtimes === 0) {
                    wx.hideLoading();
                }
                
            }
        });
    })
}